package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysConsultantAreaRel;
import com.hl.sfzy.entity.SysConsultants;
import com.hl.sfzy.service.SysConsultantAreaRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class SysConsultantAreaRelController {
    @Autowired
    private SysConsultantAreaRelService sysConsultantAreaRelService;
    @PostMapping("/sysConsultantAreaRel")
    public Result add(@RequestBody SysConsultantAreaRel sysConsultantAreaRel){
        int num = sysConsultantAreaRelService.add(sysConsultantAreaRel);
        return num > 0 ? Result.success() : Result.error();
    }
    /*
     * 删除
     * */
    @DeleteMapping("/sysConsultantAreaRel/{id}")
    public Result remove(@PathVariable("id") Integer id){
        int num = sysConsultantAreaRelService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }
    @DeleteMapping("/sysConsultantAreaRel")
    public Result removeBatch(Integer[] ids){
        int num = sysConsultantAreaRelService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();

    }
    @PutMapping("/sysConsultantAreaRel")
    public Result edit(@RequestBody SysConsultantAreaRel sysConsultantAreaRel){
        int num = sysConsultantAreaRelService.edit(sysConsultantAreaRel);
        return num > 0 ? Result.success() : Result.error();
    }
    @GetMapping("/sysConsultantAreaRel/{id}")
    public Result findById(@PathVariable("id") Integer id){
        SysConsultantAreaRel byId = sysConsultantAreaRelService.findById(id);
        return Result.success(byId);
    }

    @GetMapping("/sysConsultantAreaRel")
    public Result findAll(SysConsultantAreaRel sysConsultantAreaRel){
        List<SysConsultantAreaRel> list = sysConsultantAreaRelService.find(sysConsultantAreaRel);
        return Result.success(list);
    }

    @GetMapping("/sysConsultantAreaRel/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysConsultantAreaRel sysConsultantAreaRel) {
        Map<String, Object> map = sysConsultantAreaRelService.findPage(pageNum, pageSize,sysConsultantAreaRel);
        System.out.println(map);
        return Result.success(map);
    }
    @GetMapping("/sysConsultantAreaRel/consultant/{id}")
    public Result findByConsultId(@PathVariable("id") Integer id){
        Integer[] byConsultId = sysConsultantAreaRelService.findByConsultId(id);
        return Result.success(byConsultId);
    }

}
